package no.rodland.acc.parsers;

import org.constretto.annotation.Configuration;
import org.constretto.annotation.Configure;

import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 *
 * @Since: Jun 21, 2010 11:06:41 AM
 * @Author: fmr
 */
public class NumberParser {
    private boolean usesComma = true;
    Pattern p = Pattern.compile("(.*)\\.(.*)");

    @Configure
    public void configure(@Configuration(expression = "import.uses_comma") boolean usesComma) {
        this.usesComma = usesComma;
    }

    public Integer parse(String string) {
        if (string == null || string.length() == 0) {
            return 0;
        }
        string = string.replaceAll("[\"']", "");
        if (usesComma) {
            string = string.replaceAll(",", ".");
        }
        double d = Double.valueOf(string);
        return (int) Math.round(d);
    }
}
